package com.glsc.ngateway.common.base.domain.mysql.cmdb;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.glsc.ngateway.common.api.common.utils.DateSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Data
@Entity
@Table(name = "t_cmdb_dict")
public class CmdbDict implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "dict_id")
    private Integer dictId;

    @Column(name = "description", length = 100, columnDefinition = "varchar(100) character set utf8mb4 collate utf8mb4_0900_ai_ci")
    private String description;

    @Column(name = "dict_code", length = 50)
    private String dictCode;

    @OneToMany(fetch = FetchType.EAGER)
    @JoinColumn(name = "dict_code", referencedColumnName = "dict_code",foreignKey = @ForeignKey(name = "none",value = ConstraintMode.NO_CONSTRAINT))
    @OrderBy(value="seq ASC")
    private List<CmdbDictValue> dictValues;

    @Column(name = "dict_name", length = 30)
    private String dictName;

    @Column(name = "dict_deleted", columnDefinition = "int default '0'")
    private Integer dictDeleted;

    @Column(name = "parent_code")
    private Integer parentCode;

    @Column(name = "creator", length = 45)
    private String creator;

    @Column(name = "updator", length = 45)
    private String updator;

    @Column(name = "create_time", columnDefinition = "datetime default current_timestamp")
    @org.hibernate.annotations.CreationTimestamp
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = DateSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")//json序列化实体类处理
    @ApiModelProperty(value = "创建时间")
    @JsonIgnore
    private Date createTime;

    @Column(name = "update_time", nullable = false, columnDefinition = "datetime default current_timestamp on update current_timestamp")
    @org.hibernate.annotations.UpdateTimestamp
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = DateSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")//json序列化实体类处理
    @ApiModelProperty(value = "更新时间")
    @JsonIgnore
    private Date updateTime;
    // Getters and Setters

}

